package tothreedesignmodel.memento;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author lzhphantom
 * @Description
 * @Date 创建于 10:04 2020/7/17
 * @Modified
 */
public class CareTaker {
    private final List<Memento> mementoList = new ArrayList<>();

    public void add(Memento state) {
        mementoList.add(state);
    }

    public Memento get(int index) {
        return mementoList.get(index);
    }

    public static void main(String[] args) {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("#1");
        originator.setState("#2");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("#3");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("#4");
        careTaker.add(originator.saveStateToMemento());
        System.out.println("current :" + originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("first :" + originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("second :" + originator.getState());

    }
}
